<<<<<<< HEAD
function fun(dianji) {
    $(dianji).click(function() {
        if ($('.aside').hasClass('movein') == true) {
=======

function fun(dianji){
    $(dianji).click(function(){
        if($('.aside').hasClass('movein') == true){
>>>>>>> 086ef85d6255716b9a53ad2adcfaa9c1a741d2ee
            $('.aside').addClass('moveto').removeClass('movein')
        } else {
            $('.aside').addClass('movein').removeClass('moveto')
        }
    })
}
var shop = document.getElementsByClassName("aside-shop");
fun(shop)

// 邮箱的事件
$('.bot-sou').click(function() {
    $('.reading').toggle()
})
$('.td').click(function() {
    $('.reading').toggle()
})
$('.reading input').focus(function() {
    $(this).css('outline', '0px')
})


$('.bg-mb').height(window.screen.height)
$('.shop-mb').height(window.screen.height)

// 点击小窗口弹出及小窗口里的事件
$('.lond-lan').click(function() {
    $('.bg-mb').show()
    $('.mb').show()
})
$('.mb .con-top i').click(function() {
    $('.bg-mb').hide()
    $('.mb').hide()
})
$('.mb .bot-bot input').focus(function() {
    $(this).css('outline', '0px')
})
$('.mb .remember input').click(function() {
    $('.mb .remember').toggleClass('change')
})


// 购物车栏里点击隐藏
fun($('.aside-dis .adis-top b'))
$('.aside-dis .adis-top b').click(function() {
    $('.aside-shop .num').toggleClass('car-change')
    $('.aside-shop .num span').toggleClass('num-change')
})

// 创口滚动时top栏出现
$(window).scroll(function() {
    if (window.pageYOffset > 178) {
        $('.black-bot').css('bottom', '0')
    } else {
        $('.black-bot').css('bottom', '-48px')
    }
})

<<<<<<< HEAD
$('.top').click(function() {
=======
// 返回顶部
$('.top').click(function(){
    window.scroll(0,0)
})


$('.aside-shop .num').click(function(){
    $(this).toggleClass('car-change')
    $('.aside-shop .num span').toggleClass('num-change')
})

function reckon(){
    $('.adis-con .con-r p').text()
}

// 删除键的隐藏出现
$('.aside-dis .adis-con ul li').hover(function(){
    $(this).find('.del').css('display','block')
},function(){
    $(this).find('.del').css('display','none')
})
// 点击删除当前商品
$('.aside-dis .adis-con ul li').on('click','.del',function(){
    $(this).parents('li').remove()
    totale()
    if($('.aside-dis .adis-con ul li').length==0){
        var carts = ` <div class="con-center">
            <img src="../images/cart-nogoods.png" alt="">
            <p>购物车空空的，赶快去挑选心仪的商品吧~</p>
            <p><a href="" style="color: red;"> 去首页看看</a></p>
        </div>`;
    $('.adis-con').html(carts);
    }
})


// 渲染数据到侧栏购物车
function shopping() {
    var carts = '';
    var carsData = JSON.parse(localStorage.getItem('shoppingCart'));

    if (carsData == null || carsData.length == 0) {
        carts = ` <div class="con-center">
                    <img src="../images/cart-nogoods.png" alt="">
                    <p>购物车空空的，赶快去挑选心仪的商品吧~</p>
                    <p><a href="./index.html" style="color: red;"> 去首页看看</a></p>
            </div>`;
        $('.adis-con').html(carts);

    } else {
        var temp =`<ul></ul>`
        for (var i = 0; i < carsData.length; i++) {
            carts += `<li>
                    <div class="con-l">
                        <a href="">
                            <img src="${carsData[i].pictureURL}" alt="">
                        </a>
                    </div>
                    <div class="con-r">
                        <a href="">${carsData[i].Hometitle}</a>
                        <p>${carsData[i].Homeprice}</p>
                        <div class="con-num">
                            <span class="jian">-</span>
                            <span class="shop-num">1</span>
                            <span class="add">+</span>
                        </div>
                    </div>
                </li> `
        };
        $('.adis-con').one().html(temp)
        $(carts).appendTo('.adis-con ul');
    }
};
shopping();
$('.btnAppend').click(function() {
    shopping();
    totale()
    $('.shop-num').text($('.buyNum').val());
});

function totale(){
    // 商品总数
    var shu = 0;
    // 商品总价
    var pric=0;

    $('.aside-dis .adis-con ul li').each(function(index,value){
        shu +=Number($(this).find('.shop-num').text())
        pric +=Number($(this).find('.shop-num').text()) * Number($(this).find('p').text())
        // console.log( Number($(this).find('p').text()))
    });
    // console.log(shu);
   
    $('.aside-dis .adis-bot p span').text(shu)
    $('.aside-dis .adis-bot h4').text(pric)

    $('.aside .aside-shop span').text(shu)
}
totale()


$('.aside-dis .adis-con ul li').on('click','.add',function(){
    var sun =Number($(this).prev().text())
    sun++;
    $(this).prev().text(sun)
    totale()
})
$('.aside-dis .adis-con ul li').on('click','.jian',function(){
    var sun =Number($(this).next().text())
    sun--;
    if(sun<=0){
        $(this).parents('li').remove()
        
    }
    $(this).next().text(sun)
    totale()
    shopping();
    if($('.aside-dis .adis-con ul li').length==0){
        var carts = ` <div class="con-center">
            <img src="../images/cart-nogoods.png" alt="">
            <p>购物车空空的，赶快去挑选心仪的商品吧~</p>
            <p><a href="" style="color: red;"> 去首页看看</a></p>
        </div>`;
    $('.adis-con').html(carts);
    }
})

$('.top').click(function () {
>>>>>>> 086ef85d6255716b9a53ad2adcfaa9c1a741d2ee
    window.scroll(0, 0)
})
$('.aside-shop .num').click(function() {
    $(this).toggleClass('car-change')
    $('.aside-shop .num span').toggleClass('num-change')
});